﻿using SharePointUtilitiesForDevelopers.SitesService;

namespace SharePointUtilitiesForDevelopers.Service
{
    /// <summary>
    /// Creates Sites soap client instances.
    /// </summary>
    internal class SharePointSitesServiceClientFactory : ISharePointServiceClientFactory<SitesSoapClient, SitesSoap>
    {
        /// <summary>
        /// Creates a soap client instance.
        /// </summary>
        /// <param name="siteUrl">The site URL.</param>
        /// <returns>A soap client instance.</returns>
        public SitesSoapClient CreateInstance(string siteUrl)
        {
            // Create the service endpoint (site + service url)
            var endpointAddress = SharePointServiceUrl.GetServiceEndPointAddress(siteUrl, SharePointServiceUrl.SitesServiceUrl);

            // Create the binding
            var binding = SharePointServiceBindingFactory.CreateInstance(endpointAddress);

            // Create the proxy
            var client = new SitesSoapClient(binding, endpointAddress);

            return client;
        }
    }
}
